package com.dianping.cat.consumer.problem.model.transform;

import com.dianping.cat.consumer.problem.model.entity.Duration;
import com.dianping.cat.consumer.problem.model.entity.Entity;
import com.dianping.cat.consumer.problem.model.entity.Entry;
import com.dianping.cat.consumer.problem.model.entity.GraphTrend;
import com.dianping.cat.consumer.problem.model.entity.JavaThread;
import com.dianping.cat.consumer.problem.model.entity.Machine;
import com.dianping.cat.consumer.problem.model.entity.ProblemReport;
import com.dianping.cat.consumer.problem.model.entity.Segment;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.xml.sax.Attributes;













public class DefaultSaxMaker
  extends Object
  implements IMaker<Attributes>
{
  public String buildDomain(Attributes attributes) { throw new UnsupportedOperationException(); }


  
  public Duration buildDuration(Attributes attributes) {
/*  37 */     String value = attributes.getValue("value");
/*  38 */     String count = attributes.getValue("count");
/*  39 */     Duration duration = new Duration((value == null) ? 0 : ((Integer)convert(Integer.class, value, Integer.valueOf(0))).intValue());

/*  41 */     if (count != null) {
/*  42 */       duration.setCount(((Integer)convert(Integer.class, count, Integer.valueOf(0))).intValue());
    }
    
/*  45 */     return duration;
  }

  
  public Entity buildEntity(Attributes attributes) {
/*  50 */     String id = attributes.getValue("id");
/*  51 */     String type = attributes.getValue("type");
/*  52 */     String status = attributes.getValue("status");
/*  53 */     Entity entity = new Entity(id);

/*  55 */     if (type != null) {
/*  56 */       entity.setType(type);
    }
    
/*  59 */     if (status != null) {
/*  60 */       entity.setStatus(status);
    }
    
/*  63 */     return entity;
  }

  
  public Entry buildEntry(Attributes attributes) {
/*  68 */     String type = attributes.getValue("type");
/*  69 */     String status = attributes.getValue("status");
/*  70 */     Entry entry = new Entry();

/*  72 */     if (type != null) {
/*  73 */       entry.setType(type);
    }
    
/*  76 */     if (status != null) {
/*  77 */       entry.setStatus(status);
    }
    
/*  80 */     return entry;
  }

  
  public GraphTrend buildGraphTrend(Attributes attributes) {
/*  85 */     String duration = attributes.getValue("duration");
/*  86 */     String fails = attributes.getValue("fails");
/*  87 */     GraphTrend graphTrend = new GraphTrend((duration == null) ? 0 : ((Integer)convert(Integer.class, duration, Integer.valueOf(0))).intValue());

/*  89 */     if (fails != null) {
/*  90 */       graphTrend.setFails(fails);
    }
    
/*  93 */     return graphTrend;
  }


  
/*  98 */   public String buildIp(Attributes attributes) { throw new UnsupportedOperationException(); }


  
  public Machine buildMachine(Attributes attributes) {
/* 103 */     String ip = attributes.getValue("ip");
/* 104 */     return new Machine(ip);
  }




  
/* 111 */   public String buildMessage(Attributes attributes) { throw new UnsupportedOperationException(); }


  
  public ProblemReport buildProblemReport(Attributes attributes) {
/* 116 */     String domain = attributes.getValue("domain");
/* 117 */     String startTime = attributes.getValue("startTime");
/* 118 */     String endTime = attributes.getValue("endTime");
/* 119 */     ProblemReport problemReport = new ProblemReport(domain);

/* 121 */     if (startTime != null) {
/* 122 */       problemReport.setStartTime(toDate(startTime, "yyyy-MM-dd HH:mm:ss", null));
    }
    
/* 125 */     if (endTime != null) {
/* 126 */       problemReport.setEndTime(toDate(endTime, "yyyy-MM-dd HH:mm:ss", null));
    }
    
/* 129 */     return problemReport;
  }

  
  public Segment buildSegment(Attributes attributes) {
/* 134 */     String id = attributes.getValue("id");
/* 135 */     String count = attributes.getValue("count");
/* 136 */     Segment segment = new Segment((id == null) ? null : (Integer)convert(Integer.class, id, null));

/* 138 */     if (count != null) {
/* 139 */       segment.setCount(((Integer)convert(Integer.class, count, Integer.valueOf(0))).intValue());
    }
    
/* 142 */     return segment;
  }

  
  public JavaThread buildThread(Attributes attributes) {
/* 147 */     String groupName = attributes.getValue("group-name");
/* 148 */     String name = attributes.getValue("name");
/* 149 */     String id = attributes.getValue("id");
/* 150 */     JavaThread thread = new JavaThread(id);

/* 152 */     if (groupName != null) {
/* 153 */       thread.setGroupName(groupName);
    }
    
/* 156 */     if (name != null) {
/* 157 */       thread.setName(name);
    }
    
/* 160 */     return thread;
  }

  
  protected <T> T convert(Class<T> type, String value, T defaultValue) {
/* 165 */     if (value == null || value.length() == 0) {
/* 166 */       return defaultValue;
    }
    
/* 169 */     if (type == Boolean.class || type == boolean.class)
/* 170 */       return (T)Boolean.valueOf(value); 
/* 171 */     if (type == Integer.class || type == int.class)
/* 172 */       return (T)Integer.valueOf(value); 
/* 173 */     if (type == Long.class || type == long.class)
/* 174 */       return (T)Long.valueOf(value); 
/* 175 */     if (type == Short.class || type == short.class)
/* 176 */       return (T)Short.valueOf(value); 
/* 177 */     if (type == Float.class || type == float.class)
/* 178 */       return (T)Float.valueOf(value); 
/* 179 */     if (type == Double.class || type == double.class)
/* 180 */       return (T)Double.valueOf(value); 
/* 181 */     if (type == Byte.class || type == byte.class)
/* 182 */       return (T)Byte.valueOf(value); 
/* 183 */     if (type == Character.class || type == char.class) {
/* 184 */       return (T)Character.valueOf(value.charAt(0));
    }
/* 186 */     return (T)value;
  }

  
  protected Date toDate(String str, String format, Date defaultValue) {
/* 191 */     if (str == null || str.length() == 0) {
/* 192 */       return defaultValue;
    }
    
    try {
/* 196 */       return (new SimpleDateFormat(format)).parse(str);
/* 197 */     } catch (ParseException e) {
/* 198 */       throw new RuntimeException(String.format("Unable to parse date(%s) in format(%s)!", new Object[] { str, format }), e);
    }
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/lib/cat-consumer-3.0.0.jar!/com/dianping/cat/consumer/problem/model/transform/DefaultSaxMaker.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */